<!--
 * @Description: 缺陷信息列表
 * @Author: Liu Zhiwang
 * @Date: 2021-04-13 16:00:44
 * @LastEditTime: 2024-01-17 11:10:12
 * @LastEditors: zhangweili zhang_weili@uxsino.com
-->
<template>
  <div class="app-container v-flex JCWWTKInformation">
    <!-- 顶部操作栏 -->
    <filter-form
      :form="listQuery"
      :data="filterData01"
      :has-default-operation="false"
      @search="search">
      <el-button
        style="width: 99px;"
        class="search-btn"
        size="mini"
        type="primary"
        icon="el-icon-search"
        @click="search">查询</el-button>
      <el-button
        style="width: 99px;"
        class="refresh-btn"
        size="mini"
        type="primary"
        icon="el-icon-refresh"
        @click="resetSearch">重置</el-button>
      <el-button
        style="width: 99px;"
        size="mini"
        :icon="showSearch ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
        @click="showSearch = !showSearch, showSearch ? height = height - 76 : height = height + 76">高级搜索</el-button>
    </filter-form>
    <filter-form
      v-show="showSearch"
      :form="listQuery"
      :data="filterData02"
      :has-default-operation="false">
      <el-date-picker
        v-model="listQuery.findStartDate"
        value-format="yyyy-MM-dd"
        type="date"
        placeholder="发现开始日期"
        :picker-options="pickerFindStartDate"
        :clearable="true"
        style="margin-right: 10px;width: 150px;"
        size="mini" />
      <el-date-picker
        v-model="listQuery.findEndDate"
        value-format="yyyy-MM-dd"
        type="date"
        placeholder="发现结束日期"
        :picker-options="pickerFindEndDate"
        :clearable="true"
        style="margin-right: 10px;width: 150px;"
        size="mini" />
      <el-date-picker
        v-model="listQuery.handleStartDate"
        value-format="yyyy-MM-dd"
        type="date"
        placeholder="处理开始日期"
        :picker-options="pickerHandleStartDate"
        :clearable="true"
        style="margin-right: 10px;width: 150px;"
        size="mini" />
      <el-date-picker
        v-model="listQuery.handleEndDate"
        value-format="yyyy-MM-dd"
        type="date"
        placeholder="处理结束日期"
        :picker-options="pickerHandleEndDate"
        :clearable="true"
        style="margin-right: 10px;width: 150px;margin-bottom: 10px;"
        size="mini" />
    </filter-form>
    <!-- 顶部操作栏 -->

    <div class="content">
      <!-- 标题栏 -->
      <div class="content-header">
        <div class="content-header-vertical-bar" />
        <span class="content-header-title">缺陷信息</span>
        <div
          :class="listQuery.countMessage === 'total' ? 'content-msg-active' : 'content-msg'"
          @click="listQuery.countMessage = 'total'; search()">
          缺陷总数
          <span>{{ countData.total ? countData.total : 0 }}</span> 处
        </div>
        <div
          :class="listQuery.countMessage === 'notReformCount' ? 'content-msg-active' : 'content-msg'"
          @click="listQuery.countMessage = 'notReformCount'; search()">
          未销缺
          <span>{{ countData.notReformCount ? countData.notReformCount : 0 }}</span> 处
        </div>
        <div
          :class="listQuery.countMessage === 'reformCount' ? 'content-msg-active' : 'content-msg'"
          @click="listQuery.countMessage = 'reformCount'; search()">
          已销缺
          <span>{{ countData.reformCount ? countData.reformCount : 0 }}</span> 处
        </div>
        <div
          :class="listQuery.countMessage === 'dangerDateCount' ? 'content-msg-active' : 'content-msg'"
          @click="listQuery.countMessage = 'dangerDateCount'; search()">
          临近未处理
          <span>{{ countData.dangerDateCount ? countData.dangerDateCount : 0 }}</span> 处
        </div>
        <div
          :class="listQuery.countMessage === 'overDateCount' ? 'content-msg-active' : 'content-msg'"
          @click="listQuery.countMessage = 'overDateCount'; search()">
          超期未处理
          <span>{{ countData.overDateCount ? countData.overDateCount : 0 }}</span> 处
        </div>
        <!--<div class="operation-btn-div">
          <el-button
            v-permission-button="'ITPS-ADD'"
            class="operation-btn"
            icon="el-icon-plus"
            @click="addForm">新增</el-button>
          <el-button
            v-permission-button="'ITPS-EXPORT'"
            class="operation-btn"
            icon="el-icon-download"
            @click="exportFile">导出</el-button>
        </div>-->
      </div>
      <!-- 标题栏 -->
    </div>

    <!-- 表格 -->
    <div ref="main" class="v-flex-elastic defect-information">
      <base-table
        :height="height"
        :loading="tableData.loading"
        :data="tableData.tableList"
        :columns="tableData.columns"
        :show-index="tableData.showIndex"
        :show-selection="tableData.showSelection"
        :show-operation="tableData.showOperation"
        :show-filter-column="tableData.showFilterColumn"
        :operaton-width="tableData.operatonWidth"
        :default-operations="tableData.defaultOperations"
        :has-auth="tableData.hasAuth"
        :row-show-color="tableData.rowShowColor">
        <template slot="listStatus" slot-scope="{ row }">
          <el-tooltip
            v-if="row.listStatus === 2 || row.listStatus === 3"
            effect="dark"
            :content="`缺陷距离超期还剩${row.rectifTime}天`"
            placement="top">
            <div class="remain-color">{{ row.statusText }}</div>
          </el-tooltip>
          <el-tooltip
            v-else-if="row.listStatus === 4"
            effect="dark"
            :content="`缺陷已超期${row.rectifTime}天`"
            placement="top">
            <div class="overtime-color">{{ row.statusText }}</div>
          </el-tooltip>
          <div v-else style="padding: 5px 10px;">{{ row.statusText }}</div>
        </template>
        <template slot="auditNode" slot-scope="{ row }">
          <el-tooltip effect="dark" :content="row.itemTitle" placement="top">
            <div class="point-div">
              <div
                v-show="row.auditNode && ((row.inputAuditStatus === 2 && row.rectifAuditStatus === 0) || row.rectifAuditStatus === 2)"
                class="point-green" />
              <div
                v-show="row.auditNode && ((row.inputAuditStatus === 1 && row.rectifAuditStatus === 0) || row.rectifAuditStatus === 1)"
                class="point-blue" />
              <div
                v-show="row.inputAuditStatus === 3 || row.rectifAuditStatus === 3"
                class="point-red" />
              {{ (row.inputAuditStatus === 3 || row.rectifAuditStatus === 3) ? '已驳回' : row.auditNode }}
            </div>
          </el-tooltip>
        </template>
        <template slot="operations" slot-scope="{ row, $index }">
          <!-- 编辑 -->
          <el-button
            v-show="row.defectStatus === 0"
            v-permission-button="'ITPS-UPDATE'"
            size="mini"
            class="td-btn-operation"
            @click.native="updateForm(row, $index)">编辑</el-button>
          <!-- 编辑 -->

          <!-- 销缺 -->
          <el-button
            v-show="row.defectStatus === 2 || row.defectStatus === 7"
            v-permission-button="'ITPS-RECT'"
            size="mini"
            class="td-btn-operation"
            @click.native="updateForm(row, $index)">销缺</el-button>
          <!-- 销缺 -->

          <!-- 延期 -->
          <el-button
            v-show="row.defectStatus === 2 || row.defectStatus === 7"
            v-permission-button="'ITPS-DELAY'"
            size="mini"
            class="td-btn-operation"
            @click.native="delayForm(row, $index)">延期</el-button>
          <!-- 延期 -->

          <!-- 延期审核 -->
          <el-button
            v-show="row.defectStatus === 6 && row.deferredAuth === 1"
            v-permission-button="'ITPS-DELAY-EXAMINE'"
            size="mini"
            class="td-btn-operation"
            @click.native="delayExamineForm(row, $index)">审核</el-button>
          <!-- 延期审核 -->

          <!-- 3：工长、车间确认、4：工长、车间消缺审核 5:技术科审核 -->
          <el-button
            v-show="(row.defectStatus === 1 || row.defectStatus === 3) && row.auditAuth === 1"
            v-permission-button="'ITPS-EXAMINE'"
            size="mini"
            class="td-btn-operation"
            @click.native="examineForm(row, $index)">审核</el-button>
          <!-- 3：工长、车间确认、4：工长、车间消缺审核 5:技术科审核  -->

          <!-- 核校 -->
          <el-button
            v-show="row.defectStatus === 4"
            v-permission-button="'ITPS-CHECK'"
            size="mini"
            class="td-btn-operation"
            @click.native="checkForm(row, $index)">校核</el-button>
          <!-- 核校 -->

          <!-- 查看 -->
          <el-button
            v-permission-button="'ITPS-VIEW'"
            size="mini"
            class="td-btn-operation"
            @click.native="view(row, $index)">查看</el-button>
          <!-- 查看 -->

          <!-- 删除 -->
          <el-button
            v-show="row.defectStatus === 0"
            v-permission-button="'ITPS-DELETE'"
            size="mini"
            class="td-btn-operation"
            @click.native="deleteData(row, $index)">删除</el-button>
          <!-- 删除 -->
        </template>
      </base-table>
    </div>
    <!-- 表格 -->

    <!-- 分页 -->
    <div class="page-box">
      <pagination
        :total="tableData.total"
        :page.sync="listQuery.page"
        :size.sync="listQuery.size"
        @pagination="getListPage" />
    </div>
    <!-- 分页 -->

    <!-- 查看缺陷信息弹框组件 -->
    <look-data-dialog :dialog="lookDialog" :defect-type="defectType" />
    <!-- 查看缺陷信息弹框组件 -->

    <!-- 新增/整改缺陷信息弹框组件 -->
    <!--<data-add-or-edit
      :dialog="dialog"
      @updateData="updateData"
    @updateDataNoClose="updateDataNoClose" />-->
    <!-- 新增/整改缺陷信息弹框组件 -->

    <!-- 延期缺陷弹框组件 -->
    <data-delay :dialog="delayDialog" :defect-type="defectType" @updateData="updateData" />
    <!-- 延期缺陷弹框组件 -->

    <!-- 延期审核缺陷弹框组件 -->
    <data-delay-examine
      :dialog="delayExamineDialog"
      :defect-type="defectType"
      @updateData="updateData" />
    <!-- 延期审核缺陷弹框组件 -->

    <!-- 校核信息弹框组件 -->
    <data-check :dialog="checkDialog" :defect-type="defectType" @updateData="updateData" />
    <!-- 校核信息弹框组件 -->
  </div>
</template>

<script>
import { getListPage as getDeviceListPage, getDevClasss, deleteData as deleteDataDevice, getCount as getDefectDeviceCount } from '@/api/jcwwtk/information'
import { findManageUnitDeptList, findManageDeptTree, getLineList, getSiteByLines, getRailtypeList, getDirectionList, getTrackList, getTunnelList, defectLevelList, defectCategoryPage } from '@/api/platform'
import { getUserInfo } from '@/utils/auth'
import { tableMixin, downloadFile } from '@/utils/public'
import { getDatatime } from '@/utils'
import LookDataDialog from './components/LookDataDialog'
import DataAddOrEdit from './components/DataAddOrEdit'
import DataDelay from './components/DataDelay'
import DataDelayExamine from './components/DataDelayExamine'
import DataCheck from './components/DataCheck'

export default {
  name: 'JCWWTKInformation',
  components: {
    LookDataDialog,
    // eslint-disable-next-line vue/no-unused-components
    DataAddOrEdit,
    DataDelay,
    DataDelayExamine,
    DataCheck
  },
  mixins: [tableMixin],
  data() {
    return {
      defectType: '1', // 切换的缺陷类型：1：设备缺陷；2：树木隐患；3：鸟害；4：其他

      // 满足六个段接口请求标识
      unitDeptCode: '',

      // 表格高度
      height: 0,

      // 显示高级搜索
      showSearch: false,

      // 顶部操作栏配置
      filterData01: {
        unitDeptCode: {
          width: '160px',
          key: 'unitDeptCode',
          type: 'select',
          title: '单位',
          placeholder: '所有单位',
          options: [],
          clearable: true,
          props: { label: 'deptName', value: 'deptNo' },
          changeFn: (vm) => {
            if (vm) {
              this.unitDeptCode = vm
              this.filterData01['deptCode'].options = []
              this.filterData01['lineId'].options = []
              this.filterData01['lineSiteId'].options = []
              this.filterData01['directionId'].options = []
              this.filterData01['trackId'].options = []
              // this.filterData02['tunnelId'].options = []
              this.tableData.tableList = []
              this.listQuery = {
                page: 1,
                size: 20,
                unitDeptCode: vm,
                deptCode: '',
                railType: '',
                lineId: '',
                lineSiteId: '',
                directionId: '',
                defectInfoDesc: '',
                trackId: '',
                // tunnelId: '',
                startRoadMark: '',
                endRoadMark: '',
                status: '',
                deviceClassId: '',
                categoryName: '',
                defectGradeName: '',
                pillarNum: '',
                findStartDate: '',
                findEndDate: '',
                handleStartDate: '',
                handleEndDate: '',
                defectCategoryId: '',
                defectLevelId: '',
                countMessage: ''
              }
              this.getList() // 加载下拉信息列表
              this.getListPage() // 查询列表信息
            }
          }
        },
        // deptCode: {
        //   width: '160px',
        //   key: 'deptCode',
        //   type: 'selectTree',
        //   title: '部门',
        //   placeholder: '部门',
        //   options: [],
        //   props: {
        //     label: 'label',
        //     value: 'code',
        //     parent: 'parentId',
        //     children: 'children'
        //   }
        // },
        deptCode: {
          width: '160px',
          key: 'deptCode',
          type: 'select',
          title: '部门',
          placeholder: '部门',
          options: [],
          props: {
            label: 'label',
            value: 'id'
          }
        },
        lineId: {
          width: '160px',
          key: 'lineId',
          type: 'select',
          title: '线路',
          placeholder: '线路',
          options: [],
          props: {
            label: 'seclineName',
            value: 'seclineId'
          },
          changeFn: (vm, node) => {
            this.listQuery.lineSiteId = ''
            this.filterData01['lineSiteId'].options = []
            this.listQuery.trackId = ''
            this.filterData01['trackId'].options = []
            // this.listQuery.tunnelId = ''
            // this.filterData02['tunnelId'].options = []
            // 查询区间站场信息列表
            getSiteByLines({
              seclineId: vm
            }).then(response => {
              this.filterData01['lineSiteId'].options = response.data
            })
          },
          clearFn: () => {
            this.listQuery.lineSiteId = ''
            this.filterData01['lineSiteId'].options = []
            this.listQuery.trackId = ''
            this.filterData01['trackId'].options = []
            // this.listQuery.tunnelId = ''
            // this.filterData02['tunnelId'].options = []
          }
        },
        lineSiteId: {
          width: '160px',
          key: 'lineSiteId',
          type: 'select',
          title: '区站',
          placeholder: '区站',
          options: [],
          props: {
            label: 'siteName',
            value: 'siteId'
          },
          changeFn: (vm, node) => {
            this.listQuery.trackId = ''
            this.filterData01['trackId'].options = []
            // this.listQuery.tunnelId = ''
            // this.filterData02['tunnelId'].options = []
            // 查询股道信息列表
            getTrackList({
              unitDeptCode: this.unitDeptCode,
              siteId: vm
            }).then(response => {
              this.filterData01['trackId'].options = response.data
              this.filterData01['trackId'].options.unshift({ trackName: '非股道', trackId: 'NotTrack' })
            })
            // 查询隧道信息列表
            // getTunnelList({
            //   unitDeptCode: this.unitDeptCode,
            //   siteId: vm
            // }).then(response => {
            //   this.filterData02['tunnelId'].options = response.data
            //   this.filterData02['tunnelId'].options.unshift({ tunnelName: '非隧道', tunnelId: 'NotTunnel' })
            // })
          },
          clearFn: () => {
            this.listQuery.trackId = ''
            this.filterData01['trackId'].options = []
            // this.listQuery.tunnelId = ''
            // this.filterData02['tunnelId'].options = []
          }
        },
        directionId: {
          width: '160px',
          key: 'directionId',
          type: 'select',
          title: '行别',
          placeholder: '行别',
          options: [],
          props: {
            label: 'directionName',
            value: 'directionId'
          }
        },
        defectInfoDesc: {
          width: '160px',
          key: 'defectInfoDesc',
          type: 'input',
          title: '缺陷描述',
          placeholder: '缺陷描述'
        },
        cTypeId: {
          width: '160px',
          key: 'cTypeId',
          type: 'select',
          title: '缺陷来源',
          placeholder: '缺陷来源',
          options: [
            {
              'itemName': '1C',
              'dictionaryId': 'JCJCTYPE01'
            },
            {
              'itemName': '2C',
              'dictionaryId': 'JCJCTYPE02'
            },
            {
              'itemName': '3C',
              'dictionaryId': 'JCJCTYPE03'
            },
            {
              'itemName': '4C',
              'dictionaryId': 'JCJCTYPE04'
            },
            {
              'itemName': '5C',
              'dictionaryId': 'JCJCTYPE05'
            },
            {
              'itemName': '6C',
              'dictionaryId': 'JCJCTYPE06'
            }
          ],
          props: { label: 'itemName', value: 'dictionaryId' }
        },
        trackId: {
          width: '160px',
          key: 'trackId',
          type: 'select',
          title: '股道',
          placeholder: '股道',
          options: [],
          props: { label: 'trackName', value: 'trackId' }
        }
      },

      // 顶部操作栏配置（折叠部分）
      filterData02: {
        // tunnelId: {
        //   width: '160px',
        //   key: 'tunnelId',
        //   type: 'select',
        //   title: '隧道',
        //   placeholder: '隧道',
        //   options: [],
        //   props: { label: 'tunnelName', value: 'tunnelId' }
        // },
        startRoadMark: {
          width: '160px',
          key: 'startRoadMark',
          type: 'input',
          placeholder: '开始公里标'
        },
        endRoadMark: {
          width: '160px',
          key: 'endRoadMark',
          type: 'input',
          placeholder: '结束公里标'
        },
        status: {
          width: '160px',
          key: 'status',
          type: 'select',
          title: '销缺情况',
          placeholder: '销缺情况',
          options: [
            { name: '未销缺', value: 'N' },
            { name: '已销缺', value: 'Y' }
          ],
          props: { label: 'name', value: 'value' }
        },
        /* deviceClassId: {
          width: '160px',
          key: 'deviceClassId',
          type: 'selectTree',
          title: '设备类别',
          placeholder: '设备类别',
          options: [],
          props: {
            label: 'label',
            value: 'id',
            parent: 'parentId',
            children: 'children'
          }
        },*/
        categoryName: {
          width: '160px',
          key: 'categoryName',
          type: 'selectTable',
          title: '缺陷类型',
          placeholder: '缺陷类型',
          selectTableModel: {
            filterForm: {
              page: 1,
              size: 10,
              keyWord: ''
            },
            filterData: {
              keyWord: {
                key: 'keyWord',
                type: 'input',
                placeholder: '名称'
              }
            },
            columns: [
              { property: 'categoryName', label: '分类名称' },
              { property: 'defectLevelName', label: '缺陷等级' }
            ],
            total: 0,
            filterFn: defectCategoryPage
          },
          options: [],
          changeFn: (row) => {
            this.listQuery.defectCategoryId = row.id
            this.listQuery.categoryName = row.categoryName
          },
          clearFn: () => {
            this.listQuery.defectCategoryId = ''
            this.listQuery.categoryName = ''
          }
        },
        /* defectTypeName: {
          width: '160px',
          key: 'defectTypeName',
          type: 'select',
          title: '缺陷类型',
          placeholder: '缺陷类型',
          options: [],
          props: { label: 'categoryName', value: 'id' }
        },*/
        defectGradeName: {
          width: '160px',
          key: 'defectLevelId',
          type: 'select',
          title: '缺陷等级',
          placeholder: '缺陷等级',
          options: [],
          props: { label: 'levelName', value: 'id' }
        },
        pillarNum: {
          width: '160px',
          key: 'pillarNum',
          type: 'input',
          title: '支柱号',
          placeholder: '支柱号'
        }
      },

      // 时间区间选择
      pickerFindStartDate: this.handleFindStartDate(),
      pickerFindEndDate: this.handleFindEndDate(),
      pickerHandleStartDate: this.handleHandleStartDate(),
      pickerHandleEndDate: this.handleHandleEndDate(),

      // 查询列表请求参数
      listQuery: {
        page: 1,
        size: 20,
        unitDeptCode: '',
        deptCode: '',
        railType: '',
        lineId: '',
        lineSiteId: '',
        directionId: '',
        defectInfoDesc: '',
        trackId: '',
        // tunnelId: '',
        cTypeId: '',
        startRoadMark: '',
        endRoadMark: '',
        status: '',
        deviceClassId: '',
        categoryName: '',
        defectGradeName: '',
        pillarNum: '',
        findStartDate: '',
        findEndDate: '',
        handleStartDate: '',
        handleEndDate: '',
        defectCategoryId: '',
        defectLevelId: '',
        countMessage: '',
        unitCodeParams: ''
      },

      // 统计栏参数
      countData: {
        notReformCount: 0,
        overDateCount: 0,
        reformCount: 0,
        total: 0
      },

      // 表格数组
      tableData: {
        loading: false,
        tableList: [],
        total: 0,
        columns: [
          { label: '序号', prop: 'index', width: 50, fixed: 'left', formatter: (row, column, cellValue, index) => index + 1 },
          { label: '缺陷状态', prop: 'status', width: 110, showOverflowTooltip: 'N', fixed: 'left' },
          // { label: '审核节点', prop: 'auditNode', width: 110, showOverflowTooltip: 'N', fixed: 'left' },
          { label: '线路', prop: 'lineName', width: 100, showOverflowTooltip: 'N', fixed: 'left' },
          { label: '区间站场', prop: 'lineSiteName', width: 120, showOverflowTooltip: 'N', fixed: 'left' },
          { label: '行别', prop: 'directionName', showOverflowTooltip: 'N' },
          // { label: '股道', prop: 'trackName', showOverflowTooltip: 'N' },
          // { label: '隧道', prop: 'tunnelName', showOverflowTooltip: 'N' },
          // { label: '对应公里标', prop: 'roadMark', width: 100, showOverflowTooltip: 'N', formatter: (row) => this.formatRoad(row.roadMark) },
          { label: '公里标', prop: 'roadMark', width: 100, showOverflowTooltip: 'N', formatter: (row) => this.formatRoad(row.roadMark) },
          { label: '支柱号', prop: 'pillarNum', showOverflowTooltip: 'N', fixed: 'left' },
          { label: '设备类别', prop: 'deviceClassName', width: 160, showOverflowTooltip: 'N' },
          { label: '缺陷类型', prop: 'categoryName', width: 160, showOverflowTooltip: 'N' },
          { label: '缺陷描述', prop: 'defectDescription', width: 300, showOverflowTooltip: 'N' },
          // { label: this.defectType === '2' ? '备注' : '问题描述', prop: 'defectInfoDesc', width: 300, showOverflowTooltip: 'N' },
          { label: '缺陷来源', prop: 'originName', showOverflowTooltip: 'N' },
          { label: '缺陷等级', prop: 'levelName', showOverflowTooltip: 'N' },
          { label: '发现人', prop: 'findBy', width: 160, showOverflowTooltip: 'N' },
          { label: '发现日期', prop: 'findDate', width: 100, showOverflowTooltip: 'N' },
          // { label: '整改期限', prop: 'rectifTime', width: 100, showOverflowTooltip: 'N', formatter: (row) => (row.rectifTime ? row.rectifTimeUnitText.indexOf !== '月' ? row.rectifTime + '个月' : row.rectifTime + row.rectifTimeUnitText : '') },
          { label: '整改期限', prop: 'solveDate', width: 100, showOverflowTooltip: 'N' },
          { label: '整改责任工区', prop: 'solveWorkareaName', width: 160, showOverflowTooltip: 'N' },
          // { label: '整改人', prop: 'solvePersonal', showOverflowTooltip: 'N' },
          // { label: '整改日期', prop: 'solveDatetime', width: 100, showOverflowTooltip: 'N' }
          { label: '整改人', prop: 'handleBy', showOverflowTooltip: 'N' },
          { label: '整改日期', prop: 'handleDate', width: 100, showOverflowTooltip: 'N' }
          // { label: '处理情况', prop: 'solveMethod', width: 300, showOverflowTooltip: 'N' }
        ],
        showIndex: false,
        showSelection: false,
        showOperation: true,
        showFilterColumn: true,
        operatonWidth: '160px',
        defaultOperations: [],
        hasAuth: true,
        rowShowColor: { name: 'name', value: 0 }
      },

      // 查看信息弹框配置
      lookDialog: {
        title: '',
        visible: false,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: '',
          unitCodeParams: ''
        }
      },

      // 添加/编辑弹框配置
      dialog: {
        title: '',
        visible: false,
        disabled: false,
        loading: false,
        type: '',
        dataList: {
          directionList: [],
          sourceList: []
        },
        form: {
          id: '',
          unitCodeParams: '',
          defectStatus: 0,
          inputAuditStatus: 0
        },
        rules: {}
      },

      // 延期弹框
      delayDialog: {
        title: '',
        visible: false,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: '',
          unitCodeParams: ''
        }
      },

      // 延期审核弹框
      delayExamineDialog: {
        title: '',
        visible: false,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: '',
          unitCodeParams: ''
        }
      },

      // 校核
      checkDialog: {
        title: '',
        visible: false,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: '',
          unitCodeParams: ''
        }
      },
      deptCodeArr:[]
    }
  },
  activated() {
    this.findManageUnitDeptList()
  },
  deactivated() {
    this.lookDialog.visible = false
    this.dialog.visible = false
    this.checkDialog.visible = false
    this.delayExamineDialog.visible = false
    this.delayDialog.visible = false
  },
  mounted() {
    this.findManageUnitDeptList()
  },
  methods: {
    // 查询发现开始日期控制
    handleFindStartDate() {
      const self = this
      return {
        disabledDate(time) {
          if (self.listQuery.findEndDate) {
            return new Date(self.listQuery.findEndDate) - 8.64e6 < time.getTime()
          }
        }
      }
    },

    // 查询发现结束日期控制
    handleFindEndDate() {
      const self = this
      return {
        disabledDate(time) {
          if (self.listQuery.findStartDate) {
            return new Date(self.listQuery.findStartDate) - 8.64e7 > time.getTime()
          }
        }
      }
    },

    // 查询处理开始日期控制
    handleHandleStartDate() {
      const self = this
      return {
        disabledDate(time) {
          if (self.listQuery.handleEndDate) {
            return new Date(self.listQuery.handleEndDate) - 8.64e6 < time.getTime()
          }
        }
      }
    },

    // 查询处理结束日期控制/jcwRepairhn/defectCategory
    handleHandleEndDate() {
      const self = this
      return {
        disabledDate(time) {
          if (self.listQuery.handleStartDate) {
            return new Date(self.listQuery.handleStartDate) - 8.64e7 > time.getTime()
          }
        }
      }
    },

    // 获取当前登入人可以管理的部门所属单位列表
    findManageUnitDeptList() {
      if (this.$route.query.countMessage) {
        // 查询列表请求参数
        this.listQuery = {
          page: 1,
          size: 20,
          railType: this.$route.query.railType,
          countMessage: this.$route.query.countMessage,
          levelName: this.$route.query.levelName,
          defectLevelId: this.$route.query.defectLevelId
        }
      }
      // 获取当前登入人可以管理的部门所属单位列表
      findManageUnitDeptList().then(response => {
        var resData = response.data

        for (var i in resData) {
          if (resData[i].deptNo === '001200') {
            resData.splice(i, 1)
          }
        }
        // 通过单位标识确定接口，连接各段的数据库
        if (resData.length !== 0) {
          this.filterData01['unitDeptCode'].options = response.data
          if (getUserInfo().deptCode !== '01' || getUserInfo().superAccount !== 1) {
            this.unitDeptCode = response.data[0].deptNo
            this.listQuery.unitDeptCode = response.data[0].deptNo
          }
        }
        this.getList() // 加载下拉信息列表
        this.getListPage()
      })
    },
    // 下拉数据获取
    getList() {
      this.filterData01['deptCode'].options = []
      this.filterData01['lineId'].options = []
      this.filterData01['directionId'].options = []
      this.filterData02['defectGradeName'].options = []
      this.filterData02['categoryName'].options = []
      this.dialog.dataList.directionList = []
      this.dialog.dataList.sourceList = []
      // 获取当前登入人可以管理的部门
      findManageDeptTree({ deptCode: this.unitDeptCode }).then(response => {
        const resData = response.data
        // 控制单位不可选择
        for (const i of resData) {
          if (i.obj.unitFlag === 1) { // unitFlag: 1 为单位
            i['disabled'] = true
          }
        }
        var  itemChild=[]

        var itemChildArr=[]

        for (var item in resData) {

          itemChild=itemChild.concat(resData[item].children)
          if (resData[item].code === '001200') {
            resData.splice(item, 1)
          }else if(resData[item].code === '0129'){
            this.filterData01['deptCode'].options = itemChild
          }else if(resData[item].code === '0130'){
            this.filterData01['deptCode'].options = itemChild
          }
        }
        if (itemChild.length > 0) {
          for (const key in itemChild) {
            itemChildArr=itemChildArr.concat(itemChild[key].children)
          }
          if (itemChild[0].children.length > 0) {
            this.filterData01['deptCode'].options = itemChildArr
          }
          // console.log(itemChildArr);deptCodeArr
        }
      })
      // 查询线路树信息列表
      getLineList({ unitDeptCode: this.unitDeptCode }).then(response => {
        this.filterData01['lineId'].options = response.data
      })

      // 查询设备类型
      // getDevClasss({ unitCodeParams: this.unitCodeParams, isPage: 1 }).then(response => {
      //   this.filterData02['deviceClassId'].options = response.data
      // })
      // 查询行别信息列表
      getDirectionList({ unitDeptCode: this.unitDeptCode }).then((response) => {
        this.filterData01['directionId'].options = response.data
        this.dialog.dataList.directionList = response.data
      })
      // 查询缺陷等级列表
      defectLevelList().then((response) => {
        this.filterData02['defectGradeName'].options = response.data
      })
      // 查询缺陷分类列表
      defectCategoryPage({ page: 1, size: 10 }).then((response) => {
        this.filterData02['categoryName'].options = response.data.records
        this.filterData02['categoryName'].selectTableModel.total = response.data.total
      })
    },

    // 查询列表信息
    getListPage() {
      this.tableData.loading = true
      // 查询列表信息
      getDeviceListPage(this.listQuery).then((response) => {
        this.tableData.tableList = response.data.records
        this.tableData.total = response.data.total
        this.tableData.loading = false

        // 查询各个统计数
        getDefectDeviceCount(this.listQuery).then((response) => {
          this.countData = response.data
        })
      }).catch(() => {
        this.tableData.loading = false
      })
    },

    // 搜索
    search() {
      this.listQuery.page = 1
      this.getListPage() // 查询列表信息
    },

    // 查看
    view(row) {
      const dialog = {
        title: '查看',
        visible: true,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: row.id,
          unitCodeParams: this.unitCodeParams
        }
      }
      this.lookDialog = Object.assign(this.lookDialog, dialog)
    },

    // 新增
    addForm() {
      const dialog = {
        title: '新增缺陷信息',
        visible: true,
        disabled: false,
        loading: false,
        type: 'add',
        dataList: {
          directionList: this.dialog.dataList.directionList,
          sourceList: this.dialog.dataList.sourceList
        },
        form: {
          id: '',
          unitCodeParams: this.unitCodeParams,
          defectStatus: 0,
          inputAuditStatus: 0
        }
      }
      this.dialog = Object.assign(this.dialog, dialog)
    },

    // 编辑
    updateForm(row, index) {
      const dialog = {
        title: row.defectStatus === 2 || row.defectStatus === 7 ? '整改缺陷' : '编辑缺陷',
        visible: true,
        disabled: false,
        loading: false,
        type: 'edit',
        dataList: {
          directionList: this.dialog.dataList.directionList,
          sourceList: this.dialog.dataList.sourceList
        },
        form: {
          id: row.defectInfoId,
          unitCodeParams: this.unitCodeParams,
          defectStatus: row.defectStatus,
          inputAuditStatus: row.inputAuditStatus
        }
      }
      this.dialog = Object.assign(this.dialog, dialog)
    },

    // 延期
    delayForm(row) {
      const dialog = {
        title: '延期申请',
        visible: true,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: row.defectInfoId,
          unitCodeParams: this.unitCodeParams
        }
      }
      this.delayDialog = Object.assign(this.delayDialog, dialog)
    },

    // 延期审核
    delayExamineForm(row) {
      const dialog = {
        title: '延期审核',
        visible: true,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: row.defectInfoId,
          unitCodeParams: this.unitCodeParams
        }
      }
      this.delayExamineDialog = Object.assign(this.delayExamineDialog, dialog)
    },

    // 审核
    examineForm(row, index) {
      const dialog = {
        title: row.defectStatus === 1 ? '缺陷确认审核' : '缺陷销缺审核',
        visible: true,
        disabled: false,
        loading: false,
        type: 'examine',
        dataList: {
          directionList: this.dialog.dataList.directionList,
          sourceList: this.dialog.dataList.sourceList
        },
        form: {
          id: row.defectInfoId,
          unitCodeParams: this.unitCodeParams,
          status: row.status
        }
      }
      this.dialog = Object.assign(this.dialog, dialog)
    },

    // 校核
    checkForm(row) {
      const dialog = {
        title: '校核',
        visible: true,
        disabled: false,
        loading: false,
        type: 'view',
        dataList: {},
        form: {
          id: row.defectInfoId,
          unitCodeParams: this.unitCodeParams
        }
      }
      this.checkDialog = Object.assign(this.checkDialog, dialog)
    },

    // 添加或编辑接口
    updateData() {
      this.getListPage() // 查询列表信息
      this.dialog.loading = false
      this.dialog.visible = false
    },

    // 添加或编辑接口（不关闭弹窗）
    updateDataNoClose() {
      this.getListPage() // 查询列表信息
      this.dialog.loading = false
    },

    // 删除信息
    deleteData(row, index) {
      this.confirmBox(`确定删除序号【${index + 1}】吗?`).then(() => {
        // 删除信息
        deleteDataDevice({
          unitCodeParams: this.unitCodeParams,
          id: row.defectInfoId
        }).then(() => {
          this.notifiySuccess('删除成功!')
          this.getListPage() // 查询列表信息
        })
      }).catch(() => { })
    },

    // 导出
    exportFile() {
      this.$confirm('此操作将导出缺陷信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getListPage() // 查询列表信息
        var url = this.unitCodeParams ? `/jcwRepair${this.unitCodeParams}/defectDeviceInfo` : '/jcwRepairgz/defectDeviceInfo'
        if (this.listQuery.deptCode) {
          url += '&deptCode=' + this.listQuery.deptCode
        }
        if (this.listQuery.railType) {
          url += '&railType=' + this.listQuery.railType
        }
        if (this.listQuery.lineId) {
          url += '&lineId=' + this.listQuery.lineId
        }
        if (this.listQuery.lineSiteId) {
          url += '&lineSiteId=' + this.listQuery.lineSiteId
        }
        if (this.listQuery.directionId) {
          url += '&directionId=' + this.listQuery.directionId
        }
        if (this.listQuery.trackId) {
          url += '&trackId=' + this.listQuery.trackId
        }
        // if (this.listQuery.tunnelId) {
        //   url += '&tunnelId=' + this.listQuery.tunnelId
        // }
        if (this.listQuery.startRoadMark) {
          url += '&startRoadMark=' + this.listQuery.startRoadMark
        }
        if (this.listQuery.endRoadMark) {
          url += '&endRoadMark=' + this.listQuery.endRoadMark
        }
        if (this.listQuery.status) {
          url += '&status=' + this.listQuery.status
        }
        if (this.listQuery.deviceClassId) {
          url += '&deviceClassId=' + this.listQuery.deviceClassId
        }
        if (this.listQuery.categoryName) {
          url += '&categoryName=' + this.listQuery.categoryName
        }
        if (this.listQuery.defectGradeName) {
          url += '&defectGradeName=' + this.listQuery.defectGradeName
        }
        if (this.listQuery.pillarNum) {
          url += '&pillarNum=' + this.listQuery.pillarNum
        }
        if (this.listQuery.findStartDate) {
          url += '&findStartDate=' + this.listQuery.findStartDate
        }
        if (this.listQuery.findEndDate) {
          url += '&findEndDate=' + this.listQuery.findEndDate
        }
        if (this.listQuery.handleStartDate) {
          url += '&handleStartDate=' + this.listQuery.handleStartDate
        }
        if (this.listQuery.handleEndDate) {
          url += '&handleEndDate=' + this.listQuery.handleEndDate
        }
        if (this.listQuery.defectCategoryId) {
          url += '&defectCategoryId=' + this.listQuery.defectCategoryId
        }
        if (this.listQuery.defectLevelId) {
          url += '&defectLevelId=' + this.listQuery.defectLevelId
        }
        if (this.listQuery.countMessage) {
          url += '&countMessage=' + this.listQuery.countMessage
        }
        const fileName = `${getDatatime(new Date())}缺陷信息.xls`
        downloadFile({ url, fileName })
      }).catch(() => {
        this.notifiyInfo('已取消操作!')
      })
    },

    resetSearch() { // 重置
      this.listQuery = {
        page: 1,
        size: 20,
        unitDeptCode: '',
        deptCode: '',
        railType: '',
        lineId: '',
        lineSiteId: '',
        directionId: '',
        defectInfoDesc: '',
        trackId: '',
        // tunnelId: '',
        startRoadMark: '',
        endRoadMark: '',
        status: '',
        deviceClassId: '',
        categoryName: '',
        defectGradeName: '',
        pillarNum: '',
        findStartDate: '',
        findEndDate: '',
        handleStartDate: '',
        handleEndDate: '',
        defectCategoryId: '',
        defectLevelId: '',
        countMessage: '',
        unitCodeParams: ''
      }

      this.getListPage() // 查询列表信息
    }
  }
}
</script>

<style lang="scss" scope>
.defect-information .el-table--medium td {
  padding: 0px !important;
}
.defect-information .el-table--border td:first-child .cell {
  padding-left: 0px;
  padding-right: 0px;
}
.remain-color {
  background: #f5f685;
  padding: 5px 10px;
}
.overtime-color {
  color: #ffffff;
  background: #f44b53;
  padding: 5px 10px;
  border-radius: 4px;
}

.point-div {
  display: flex;
  align-items: center;
  justify-content: left;
  .point-green {
    min-width: 6px;
    width: 6px;
    height: 6px;
    border-radius: 100px;
    background-color: #38f841;
    margin-right: 8px;
  }
  .point-blue {
    min-width: 6px;
    width: 6px;
    height: 6px;
    border-radius: 100px;
    background-color: #379df9;
    margin-right: 8px;
  }
  .point-red {
    min-width: 6px;
    width: 6px;
    height: 6px;
    border-radius: 100px;
    background-color: #f44b52;
    margin-right: 8px;
  }
}

.JCWWTKInformation {
  .refresh-btn {
    background-color: #3dbed5;
    border: none;
  }
  .refresh-btn:hover {
    background-color: #73cddd;
    border: none;
  }
  .content {
    position: relative;
    background-color: #ffffff;
    padding: 20px 30px;
    .content-header {
      height: 36px;
      display: flex;
      align-items: center;
      .content-header-vertical-bar {
        width: 7px;
        height: 26px;
        background: #409eff;
        border-radius: 4px;
        margin-right: 13px;
      }
      .content-header-title {
        font-size: 28px;
        margin-right: 30px;
      }
      .content-msg {
        width: 162px;
        height: 28px;
        margin-right: 18px;
        line-height: 26px;
        color: #323232;
        font-size: 14px;
        text-align: center;
        background: #f7fbff;
        border: 1px solid #e3e3e3;
        border-radius: 14px;
        cursor: pointer;
        span {
          color: #f44b53;
          font-size: 16px;
        }
      }
      .content-msg-active {
        width: 162px;
        height: 28px;
        margin-right: 18px;
        line-height: 26px;
        color: #ffffff;
        font-size: 14px;
        text-align: center;
        background: #409eff;
        border: 1px solid #e3e3e3;
        border-radius: 14px;
        cursor: pointer;
        span {
          color: #ffffff;
          font-size: 16px;
        }
      }
      .operation-btn-div {
        position: absolute;
        right: 28px;
        .operation-btn {
          padding: 10px 20px 10px 20px;
          margin-left: 11px;
          color: #2d6dd4;
          background-color: #e2f0fd;
          border-radius: 4px;
          border: none;
        }
        .operation-btn:hover {
          padding: 10px 20px 10px 20px;
          margin-left: 11px;
          color: #2d6dd4;
          background-color: #b0d1f0;
          border-radius: 4px;
          border: none;
        }
      }
    }
  }
  .el-date-editor .el-range__icon {
    margin-top: -6px;
  }
  .el-dialog .el-dialog__body {
    max-height: calc(80vh - 30px) !important;
    padding: 20px 20px;
  }
  .el-dialog .el-dialog__body .el-form {
    padding: 0;
  }
  .el-dialog .el-dialog__footer .el-button {
    width: auto;
  }
}
</style>
